/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javamail.sdp.util;
/**
 *
 * @author sriram
 */
public enum eRtpStaticPayload {
    //TODO: implement javax SDP payloads.
    NIL(255, "NIL", "NIL", 0),
    PCMU(0, "PCMU", "A", 8000),
    GSM(3, "GSM", "A", 8000),
    G723(4, "G723", "A", 8000),
    PCMA(8, "PCMA", "A", 8000),
    CN(13, "CN", "A", 8000),
    G729(18, "G729", "A", 8000),
    RFC2833(101, "telephone-event", "A", 8000);
    
    private final int payload;
    private final String encoding_name;
    private final String media_type;
    private final int clock_rate;
    
    
    eRtpStaticPayload(int payload, String encoding_name, String media_type, int clkrate) {
        this.payload = payload;
        this.encoding_name = encoding_name;
        this.media_type = media_type;
        this.clock_rate = clkrate;
    }
    
    public int payload() {
        return payload;
    }
 
    @Override
    public String toString() {
        return encoding_name+"/"+clock_rate;
    }
    
    public int clockrate() {
        return clock_rate;
    }
    
    public static eRtpStaticPayload fromPayload(int payload) {
        //Convert to Lower case and trim the string
        for (eRtpStaticPayload pIndex : eRtpStaticPayload.values()) {
            if(pIndex.payload == payload)
                return pIndex;
        }
        return NIL;
    }
    
    public static eRtpStaticPayload fromName(String name) {
       if(name == null)
           return NIL;
       name = name.trim().toLowerCase();
        //Convert to Lower case and trim the string
        for (eRtpStaticPayload pIndex : eRtpStaticPayload.values()) {
            if(pIndex.encoding_name.trim().toLowerCase().equals(name))
                return pIndex;
        }
        return NIL;
    }
}
